<script>
	import {
		requestData
	} from './utils/http'
	export default {
		globalData: {
			text: '1，泳安30-用户小程序',
			//WebUrl: 'https://ya30wxmp.hbwlife.com/', //线上
			//WebUrl: 'https://ya30wxmp-dev.hbwlife.com/', //线上-dev
			//WebUrl: 'http://localhost:8080/',
			WebUrl: 'http://192.168.30.52:8080/'
		},
		onLaunch() {
			//   // 打开调试
			//   uni.setEnableDebug({
			//     enableDebug: true,
			//   })
			this.fnlogin()
		},
		onLoad(option) {},
		onShow: function() {},
		methods: {
			fnlogin() {
				//console.log('app vue login')
				let user_id = uni.getStorageSync('user_id')
				if (!user_id) {
					uni.login({
						success: (res) => {
							uni.request({
								url: 'https://ya30api.hbwlife.com/wxmp/wxaccess/mp/user/login',
								method: 'POST',
								header: {},
								data: {
									wxlogin_code: res.code,
								},
								success: (ress) => {
									if (ress.data.code == 0) {
										uni.removeStorageSync('access_token')
										uni.removeStorageSync('mobile')
										uni.removeStorageSync('avatarUrl')
										uni.setStorageSync(
											'open_id',
											ress?.data?.datas?.open_id || ''
										)
										uni.setStorageSync(
											'user_id',
											ress?.data?.datas?.user_id || ''
										)
										uni.setStorageSync('mobile', ress?.data?.datas.mobile ||
											'')
										uni.setStorageSync(
											'avatarUrl',
											ress?.data?.datas.avatarUrl || ''
										)
										uni.setStorageSync(
											'access_token',
											ress?.data?.datas?.access_token || ''
										)
									} else {
										uni.showToast({
											title: ress.msg,
											icon: 'none',
										})
									}
								},
								complete: () => {},
								fail: (err) => {
									reject(err)
								},
							})
						},
					})
				}
			},
		},
		onHide: function() {},
	}
</script>
<style lang="scss">
	/* 注意要写在第一行，同时给style标签加入lang="scss"属性 */
	@import '@/uni_modules/uview-ui/index.scss';

	page {
		font-size: 32rpx !important;
	}

	uni-toast .uni-toast__content {
		font-size: 28rpx;
		white-space: pre-wrap;
	}
</style>
.